﻿using System;
using ILRuntime.CLR.Method;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;

namespace Smart.Model
{
    [ILAdapter]
    public class IDisposableClassInheritanceAdaptor : CrossBindingAdaptor
    {
        public override Type BaseCLRType
        {
            get
            {
                return typeof(IDisposable);
            }
        }

        public override Type AdaptorType
        {
            get
            {
                return typeof(Adaptor);
            }
        }

        public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance)
        {
            return new Adaptor(appdomain, instance);
        }

        public class Adaptor : MyAdaptor, IDisposable
        {
            public Adaptor(ILRuntime.Runtime.Enviorment.AppDomain appDomain, ILTypeInstance instance) : base(appDomain, instance)
            {
            }

            protected override AdaptHelper.AdaptMethod[] GetAdaptMethods()
            {
                return new AdaptHelper.AdaptMethod[]
                {
                    new AdaptHelper.AdaptMethod{ Name = "Dispose", ParamCount = 0},
                };
            }

            public void Dispose()
            {
                Invoke(0);
            }
        }
    }
}